package main

import (
	"fmt"
)

/**
 * 断言
 */
func main() {
	assert01()
	findType(20)
	findType("abc")
}

func assert01() {
	var i interface{} = 100
	t1 := i.(int)
	fmt.Println(t1)

	t2, ok := i.(string)
	if ok {
		fmt.Println(t2)
	} else {
		fmt.Println(ok)
	}

}

/**
 * type switch格式判断类型
 */
func findType(i interface{}) {
	switch x := i.(type) {
	case int:
		fmt.Println(x, "is int")
	case string:
		fmt.Println(x, "is string")
	case nil:
		fmt.Println(x, "is nil")
	default:
		fmt.Println(x, "not type matched")
	}
}
